#coding=utf-8

class Item:
    def __init__(self, id, title, name , num):
        self.id= id
        self.title = title
        self.name = name
        self.num = num

    def __repr__(self):
        return '<Item {} {}>'.format(self.id, self.name)

    # def __getattr__(self, key):
    #     if key in self.__dict__:
    #         return getattr(self, key)
    #     else:
    #         return None
    #
    # def __setattr__(self, key, value):
    #     if key in self.__dict__:
    #         setattr(self, key, value)
    #     else:
    #         print "this key is not in Item"

    # def __eq__(self, other):
    #     if isinstance(other, Item):
    #         return hash(self)==hash(other)
    #     else:
    #         return False

    def __cmp__(self, other):
        if isinstance(other, Item):
            return cmp(hash(self), hash(other))
        else:
            return False

    def __hash__(self):
        return hash(self.name+self.id)

    def __getitem__(self, key):
        # if key in self.__dict__:
        #     return self.key
        # else:
        #     return None
        return self.__dict__.get(key)

    def __setitem__(self, key, value):
        # if key in self.__dict__:
        #     self[key]=value
        # else:
        #     print ''
        self.__dict__.update(dict(key, value))

    def __delitem__(self, key):
        if key in self.__dict__:
            self.__dict__['key']=''
        else:
            pass


